var fun={
    init:function () {
        //默认查询代办的
        fun.querySubscribeInfos(10,'tab2Content1');
    },
    //获取预约信息  预约状态:-20:预约失败，10:已提交预约，20:预约成功 为空则是全部*/
    querySubscribeInfos:function (subscribeState,tabId) {
        var req={
            baseRequest:{
                pageNum:0,
                pageSize:3000
            },
            openId:-1,
            subscribeState:subscribeState
        };
        var opts = {
            method: 'post',
            url: dataUrl.util.queryAdminSubscribeInfos(),
            data: JSON.stringify(req),
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function (res) {
                if (res.code != '8888') {
                    new $.zui.Messager(res.msg, {
                        type:'danger',
                        time:'3000',
                        icon: 'heart',
                        placement: 'bottom' // 定义显示位置
                    }).show();
                    return false;
                }
                var pageBean = res.data;
                $('#dbnum').val(pageBean.pageTotals);
                var tabContent = "";
                var i=0;
                $.each(pageBean.dataList,function(index,order){
                    //出发地，目的的
                    var cityStr = order.fromCityName +'-'+order.toCityName;
                    var carType = (order.carType==1)?'小轿车':'商务车';
                    var subType = order.subscribePeopNum+'人'+((order.subscribeType==1)?'拼车':'包车');
                    tabContent += '<div class="panel panel-default">' +
                        '                <div class="panel-heading " id="headingOne">' +
                        '                    <h4 class="panel-title">' +
                        '                        <a data-toggle="collapse" class="taxi-cursor" data-parent="#accordionPanels" href="#collapseOne'+tabId+i+'">' +
                        '                            <div>' +
                        '                                <div class="float-left bj_timesta" >'+DateUtils.long2String(order.subscribeTime,1)+'</div>' +
                        '                                <div class="float-left bj_cityName taxi-hidden-nowrap" title="'+cityStr+'">'+cityStr+'</div>' +
                        '                                <div class="float-left bj_type" >'+carType+'</div>' +
                        '                            </div>' +
                        '                            <div class="pos_rel">' +
                        '                                <div class="float-left bj_schUser" >'+subType+'</div>' +
                        '                                <div class="float-left bj_usertel" ><a class="color-common" href="tel:'+order.phoneNo+'">'+order.phoneNo+'</a></div>' +
                        '                                <div class="pos_abs bj_sort"><i class="icon icon-sort"></i></div>' +
                        '                            </div>' +
                        '                        </a>' +
                        '                    </h4>' +
                        '                </div>' +
                        '                <div id="collapseOne'+tabId+i+'" class="panel-collapse collapse">' +
                        '                    <div class="panel-body">' +
                        '                        <p>备注:'+order.remarks+'</p>'+
                        '                        <div class="sch_pfoot margin-top-10" subscribe-id="'+order.id+'">';
                    if(order.subscribeState == 10){
                        tabContent +=
                            '<div class=""><button class="btn btn-primary" type="button">预约成功</button></div>' +
                            '<div class=""><button class="btn btn-warning" type="button">虚假信息</button></div>';
                    }
                    tabContent += '</div>' +
                    '                    </div>' +
                    '                </div>' +
                    '            </div>';
                    i++;
                });
                $('#'+tabId).html(tabContent);
            }
        };
        sysAjax(opts);
    },
    //更改预约订单状态
    updateSubscribeState:function(id,subscribeState){
        var opts = {
            method:'post',
            url:dataUrl.util.updateSubscribeState(),
            data:"id="+id+"&subscribeState="+subscribeState,
            contentType: 'application/x-www-form-urlencoded; charset=utf-8',
            dataType: 'json',
            success: function(res) {
                if (res.code == '8888') {
                    //刷新该界面
                    fun.querySubscribeInfos(10,'tab2Content1');
                    new $.zui.Messager('成功', {
                        type:'success',
                        time:'3000',
                        placement: 'bottom' // 定义显示位置
                    }).show();
                }else{
                    new $.zui.Messager(res.msg, {
                        type:'danger',
                        time:'3000',
                        icon: 'heart',
                        placement: 'bottom' // 定义显示位置
                    }).show();
                }
            }
        };
        sysAjax(opts);
    }
};
fun.init();

$('[data-tab]').on('show.zui.tab', function(e) {
    if(e.target.dataset.target=='#tab2Content1'){
        //待处理
        fun.querySubscribeInfos(10,'tab2Content1');
    }else if(e.target.dataset.target=='#tab2Content2'){
        //已完成
        fun.querySubscribeInfos(20,'tab2Content2');
    }else if(e.target.dataset.target=='#tab2Content3'){
        //已作废
        fun.querySubscribeInfos(-10,'tab2Content3');
    }
});
//预约成功按钮
$(document).on('click','.btn-primary',function () {
    _this=$(this);
    var subscribeId=_this.parent().parent().attr('subscribe-id');
    fun.updateSubscribeState(subscribeId,20);
});
//虚假信息按钮
$(document).on('click','.btn-warning',function () {
    _this=$(this);
    var subscribeId=_this.parent().parent().attr('subscribe-id');
    fun.updateSubscribeState(subscribeId,-10);
});